from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.bitflyer_v1.kr_rest.constants import currency_list, fiat_list
from coin.exchange.bitflyer_v1.kr_rest.currency import BitflyerCurrency


class BitflyerProduct(NativeProduct):
  _exchange = "Bitflyer"
  NativeCurrencyType = BitflyerCurrency

  def __init__(self, base, quote):
    assert base.currency in currency_list, base
    assert quote.currency in fiat_list, quote
    super().__init__(base, quote, "%s_%s" % (base.native_symbol, quote.native_symbol))

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    assert isinstance(product, str), type(product)
    for quote in fiat_list:
      if product.endswith(quote):
        base = product[:product.index(quote)]
        assert base in currency_list
        return BitflyerProduct(BitflyerCurrency.FromStrNativeCurrency(base),
                               BitflyerCurrency.FromStrNativeCurrency(quote))
    raise ValueError(product)
